<template>
<el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
            <el-form-item>
                <el-date-picker v-model="dataForm.rentDateStart" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
                </el-date-picker>
                <span>至</span>
                <el-date-picker value-format="yyyy-MM-dd" v-model="dataForm.rentDateEnd" type="date" placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="query()">搜索</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="getval();addOrUpdateHandle()">批量定价</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle" style="width: 100%">
            <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
            <el-table-column prop="roomNumber" label="房号" header-align="center" min-width="120" align="center"></el-table-column>
            <el-table-column prop="rentDate" label="日期" header-align="center" min-width="120" align="center">

            </el-table-column>
            <el-table-column prop="rentWeek" label="星期" header-align="center" align="center">
                <template slot-scope="scope">
                    {{weeksName[scope.row.rentWeek]}}
                </template>
            </el-table-column>
            <el-table-column prop="price" label="价格" header-align="center" min-width="120" align="center"></el-table-column>
            <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
                <template slot-scope="scope">
                    <el-button type="text" size="small" @click="setPrice(scope.row.id)">修改价格</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
        </el-pagination>
        <!-- 弹窗, 新增 / 修改 -->
        <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" :houseBaseId=this.dataForm.houseBaseId :roomNumbers="this.roomNumbers" @refreshDataList="getDataList"></add-or-update>
    </div>
</el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
import AddOrUpdate from "./priceSetList-add-or-update";
export default {
    mixins: [mixinViewModule],
    data() {
        return {
            mixinViewModuleOptions: {
                createdIsNeed: false,
                getDataListURL: "/hotel/house/room/page",
                getDataListIsPage: true,
                deleteURL: "/hotel/house/room",
                deleteIsBatch: true,
            },
            roomNumbers: [],
            weeksName: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
            dataForm: {
                houseBaseId: '',
                rentDateEnd: '',
                rentDateStart: ''
            },
            dialogFormVisible: false,
        };
    },
    components: {
        AddOrUpdate,
    },
    created() {
        this.dataForm.houseBaseId = this.$route.query.id;
        this.roomNumbers = this.$route.query.roomNumbers;
        this.getDataList();
    },
    mounted() {},
    methods: {
        getval() {
            //  this.roomNumbers=this.dataList[0].roomNumber.split(',');
        },
        setPrice(id) {
            this.$prompt('请输入价格', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /\d/,
            }).then(({
                value
            }) => {
                if (value) {
                    this.$http.put('/hotel/house/room', {
                        price: value,
                        id: id
                    }).then(res => {
                        if (res.code !== 0) {
                            return this.$message.error(res.msg);
                        }
                        this.$message({
                            message: this.$t("prompt.success"),
                            type: "success",
                            duration: 500,
                            onClose: () => {
                                this.visible = false;
                                this.getDataList();
                            },
                        });
                    })
                }
            }).catch(() => {

            });
        }
    },
};
</script>
